<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 搜索区域 -->
      <el-input placeholder="请输入内容"
                v-model="searchText">
        <el-button slot="append"
                   icon="el-icon-search"></el-button>
      </el-input>
      <!-- tab栏区域 -->
      <el-table :data="orderList"
                style="width: 100%"
                border>
        <el-table-column type="index"
                         width="60">
        </el-table-column>
        <el-table-column prop="order_number"
                         label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price"
                         label="订单价格"
                         width="100">
        </el-table-column>
        <el-table-column prop="order_pay"
                         label="是否付款"
                         width="100">
          <template slot-scope="scope">

            <el-tag type="danger"
                    v-if="scope.row.order_pay === '0'">未付款</el-tag>
            <el-tag type="success"
                    v-else-if="scope.row.order_pay === '1'">已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send"
                         label="是否发货"
                         width="100">
        </el-table-column>
        <el-table-column prop="update_time"
                         label="下单时间"
                         width="180">
        </el-table-column>
        <el-table-column prop="date"
                         label="操作"
                         width="180">
          <template>
            <el-button type="primary"
                       class="el-icon-edit"
                       size="mini"
                       @click="editOrder"></el-button>
            <el-button type="success"
                       class="el-icon-location-outline"
                       size="mini"
                       @click="progressBtn"></el-button>
          </template>

        </el-table-column>
      </el-table>
      <!-- 分页功能 -->
      <!-- <el-pagination @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :current-page="queryInfo.pagenum"
                     :page-sizes="[5, 10, 15, 20]"
                     :page-size="5"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination> -->
      <el-pagination @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :current-page="queryInfo.pagenum"
                     :page-sizes="[5, 8, 10, 15]"
                     :page-size="queryInfo.pagesize"
                     layout="total, sizes, prev, pager, next, jumper,slot"
                     :total="total">

      </el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog title="修改地址"
               :visible.sync="eidtDialogVisible"
               width="50%"
               @close="eidtClose">

      <el-form :model="addressForm"
               :rules="addressRules"
               ref="addressRef"
               label-width="100px">
        <el-form-item label="省市区/县"
                      prop="address1">
          <el-cascader v-model="addressForm.address1"
                       :options="cityData"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址"
                      prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer"
            class="dialog-footer">
        <el-button @click="eidtDialogVisible = false">取 消</el-button>
        <el-button type="primary"
                   @click="eidtDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流进度对话框 -->
    <el-dialog title="物流进度"
               :visible.sync="progressVisible"
               width="50%">

      <el-timeline>
        <el-timeline-item v-for="(item, index) in progressInfo"
                          :key="index"
                          :timestamp="item.time">
          {{item.context}}
        </el-timeline-item>
      </el-timeline>

    </el-dialog>
  </div>

</template>
<script>
import cityData from './citydata.js'
export default {
  data () {
    return {
      // 查询的信息
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      // 总条数
      total: 0,
      // 订单列表
      orderList: [],
      // 搜索内容
      searchText: '',
      // 修改地址的显示隐藏
      eidtDialogVisible: false,
      addressForm: {},
      addressRules: {
        address1: [
          { required: true, message: '请输入省市区/县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      cityData,
      // 物流进度对话框显示隐藏
      progressVisible: false,
      // 物流信息
      progressInfo: []
    }
  },
  methods: {
    // 获取订单列表
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo
      })
      console.log(res)

      if (res.meta.status !== 200) return this.$message.error('获取订单信息失败')
      this.orderList = res.data.goods
      this.queryInfo.pagenum = res.data.pagenum - 0
      this.total = res.data.total
      console.log(this.queryInfo)
    },

    handleSizeChange (pagesize) {
      this.queryInfo.pagesize = pagesize
      this.getOrderList()
    },
    handleCurrentChange (pagenum) {
      this.queryInfo.pagenum = pagenum
      this.getOrderList()
    },
    // 点击修改
    editOrder () {
      this.eidtDialogVisible = true
    },
    eidtClose () {
      this.$refs.addressRef.resetFields()
    },
    // 查看物流信息
    async progressBtn () {
      const { data: res } = await this.$http.get('/kuaidi/1106975712662')
      console.log(res)
      if (res.meta.status !== 200) return this.$message.error('获取物流信息失败')
      this.progressInfo = res.data
      this.progressVisible = true
      console.log(this.progressInfo)
    }

  },
  created () {
    this.getOrderList()
  }
}
</script>
<style lang="less" scoped>
@import "../../plugins/timeline/timeline.css";
@import "../../plugins/timeline-item/timeline-item.css";
.el-input-group {
  width: 300px;
  margin: 20px 0;
}
</style>
